<template>
	<view class="center">
		<view class="nav">
			<uni-easyinput class="uni-mt-5" suffixIcon="search" v-model="info.keyword"
				placeholderStyle="font-size:30rpx" placeholder="搜索内容" @iconClick="iconClick"></uni-easyinput>
			<view class="box" @click="del">
				<image src="@/static/image/personalcenter/del.png" mode=""></image>
				<view class="">
					全部删除
				</view>
			</view>
		</view>
		<uni-list :border="false">

			<uni-swipe-action v-if="showList.length!==0">
				<uni-swipe-action-item v-for="(item,index) in showList" :key='index'>
					<xbd-news-card :msgInfo='item' @click='lookDetail(item.col_id)'></xbd-news-card>
					<template v-slot:right>
						<view class="swipe_right" @click="clickDel(item.col_id)">
							<view class="">
								删除
							</view>
						</view>
					</template>
				</uni-swipe-action-item>
			</uni-swipe-action>

			<xbd-null-list v-if="!showList.length"></xbd-null-list>
			<xbd-loading-more v-if="showList.length" :status-num="statusNum" :is-load-more="isLoadMore">
			</xbd-loading-more>
		</uni-list>
		<xbd-popup :isShow="showDialog" @dialogConfirm='dialogConfirm' @dialogCancel='dialogCancel' title="全部清空"
			content="确认将我的收藏全部清空？"></xbd-popup>
	</view>
	
</template>

<script>
	import {
		Personalcenter
	} from '@/api/index.js';
	export default {
		data() {
			return {
				statusNum: 0,
				isLoadMore: false,
				showDialog: false,
				value: '',
				isOpened: 'right',
				showList: [],
				info: {
					page: 1,
					perpage: 10,
					keyword: ''
				}
			};
		},
		methods: {
			lookDetail(val) {
				uni.navigateTo({
					url: `/pages/personalcenter/collection/detail?id=${val}`,
				});
			},
			iconClick() {
				console.log('搜索')
				this.info.page=1;
				this.init()
			},
			del() {
				console.log('清空')
				this.showDialog = true
				
			},
			 async clickDel(val) {
				console.log(this.showList)
				const res = await Personalcenter.posCollectionCancel(val)
				console.log(res)
				this.showList = this.showList.filter(item => {
					return item.col_id !== val
				})
				
			},
			dialogConfirm() {
				//弹出框确认操作
				this.cancel()
				this.showList = []
				this.showDialog = false;
				console.log("确认")
			},
			dialogCancel() {
				console.log("取消")
				this.showDialog = false;
			},
			async init() {
				const res = await Personalcenter.getCollectionList(this.info)
				console.log(res)
				if (res.data.list.length === this.info.perpage) {
					this.isLoadMore = true;
					this.statusNum = 2;
				}
				this.showList = res.data.list
			},
			 async cancel(){
				const res = await Personalcenter.posAllCancel()
			},
			// 加载更多
			loadmore() {
				this.info.page++;
				this.statusNum = 1;
				this.isLoadMore = true;
				this.loadmoreList();
			},
			async loadmoreList() {
				try {
					const res = await Personalcenter.getCollectionList(this.info);
					if (res.data.list.length) {
						this.showList = this.showList.concat(res.data.list);
						if (res.data.list.length === this.info.perpage) {
							this.statusNum = 2;
						} else {
							this.statusNum = 0;
						}
						// this.isLoadMore = false;
					} else {
						this.info.page--;
						this.statusNum = 0;
					}
				} catch (e) {
					uni.hideLoading();
					this.info.page--;
				}
			},

		},
		onReachBottom() {
			// 当下拉组件显示状态 并且显示不是没有数据了 时才进行下拉加载
			if (this.isLoadMore && this.statusNum !== 0) {
				this.loadmore();
			}
		},
		async onLoad() {
			await this.init()
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-icons {
		margin-right: 20rpx;
	}

	::v-deep .uni-easyinput__content-input {
		font-size: 30rpx;
	}
	::v-deep .uni-easyinput__content {
		height: 72rpx !important;
	}
	.center {
		padding: 32rpx;

		.uni-mt-5 {
			font-size: 30rpx;
		}

		.nav {
			display: flex;
			align-items: center;

			.box {
				font-size: 22rpx;
				margin-left: 40rpx;
				width: 88rpx;
				color: #8890A5;

				image {
					margin-left: 26rpx;
					width: 30rpx;
					height: 30rpx;
				}
			}

		}
	}

	.swipe_right {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 144rpx;
		height: 104rpx;
		background: #fc4f4f;
		font-size: 32rpx;
		color: #FFFFFF;
		margin-top: 30rpx;
	}
</style>
